//选项卡函数
function changeTab(opt) {
	var tabs = opt.tabs,
		tabInfo = opt.tabInfo,
		activeClass = opt.activeClass,
		eventName = opt.eventName || "click";

	tabs.bind(eventName, function() {
		var index = tabs.index(this);

		tabs.removeClass(activeClass);
		$(this).addClass(activeClass);

		tabInfo.css("display", "none");
		tabInfo.eq(index).css("display", "block");
	});
}
function reloadFooter(){
	var docHeight=$(document).height();
	var footerHeight=$("#footer").height();
	var windowHeight = $(window).height();
	if (docHeight>windowHeight) {
		$("#footer").attr("class","");
	} else {
		$("#footer").attr("class","fixed_footer");
	}
}

//访问电脑版网站
function visitPC() {
	var url = "http://www.u17.com?qAccess=1";
	$.cookie("qAccess","1",{path:"/",domain:"u17.com"});
	//漫画详情页，也跳转电脑版的漫画详情页
	var reg = new RegExp(".*/c/(\\d*).html");
	var r=new String(window.location.href).match(reg);
	if(r!=null){
		window.location.href="http://www.u17.com/comic/"+r[1]+".html?qAccess=1";
	}else{
		window.location.href=url;
	}
}
function goLoginPage(url){
	if(!url)url = document.URL;
	var b = new Base64();
	var u = b.encode(url);
	u=u.replace("/","_"); 
	//window.location.href = pUrl+"/authorization?u="+u;
	//window.location.href=pUrl+"/user/login?uri="+u;
	var login_dialog_box =  $('#login_dialog_box');
	if(! login_dialog_box.attr('proccess')){
		login_dialog_box.find('a').each(function(ind,obj){
			var obj = $(obj), h = obj.attr('href');
			if(obj.attr('class').indexOf('u17')!=-1){
				if(h)obj.attr('href',  h+'?u='+u);
			}else{
				if(h)obj.attr('href',  h+encodeURIComponent('?u='+u));
			}
			 
		});
		login_dialog_box.attr('proccess','1');
	}
	$('div.mark').css('display','block');
	login_dialog_box.toggle(500);
	login_dialog_box.find('a.close').click(function(){
		login_dialog_box.hide();
		$('div.mark').css('display','none');
	});
}
//分类下拉
$(function(){
	$('a').mousedown(function(){return false;});
	$('.categray').click(function(){
		if($('.categray').hasClass('cur')){
			$('.categray').removeClass('cur');
			$('.categray').find('b').removeClass('cur');
			$('.categray_box').hide();
		}else{
			$('.categray').addClass('cur');
			$('.categray').find('b').addClass('cur');
			$('.categray_box').show();			
		}
	});
});
//点击反馈效果
function favorite(){
	var user = get_user();
	if(user!=null && user.id>0) {
		return true;
	} else {
		m_dlg.showPrompt({content:"登陆后才能用哦",autoClose:2,onclosed:function(){global.goLoginPage();}});
		return false;
	}
};
//隔行变色
$(function(){
	//章节列表
	$('.comic_list_con ul li:odd').addClass('odd');
	//搜索结果页
	$('.serach_box_bg div:odd').addClass('odd');	
	//书架页
	$('.shelf_con:odd').addClass('odd');
	//分类列表页
	$('.search_result_box:odd').addClass('odd');
});

$(function(){
	//漫画详情页简介
	$('.intro .arrow').click(function(){
		if($('.intro p').height()==50){
			$('.intro p').css({'height':'auto','overflow':'auto'});
			$('.intro .arrow b').addClass('cur');	
		}else{
			$('.intro p').css({'height':50+'px','overflow':'hidden'});
			$('.intro .arrow b').removeClass('cur');		
		}	
	});
});

//底部app下载广告显示
$(function(){
	var showAppDownload=$.cookie("showAppDownload");
	var ref=$.cookie("ref");
	console.log("ref="+ ref);
	if(showAppDownload){
		$(".down_app").hide();
		$(".zhanbei").hide();
	}
	//1252950557如果是百度轻应用,隐藏下载，通过审核后在开通下载；注释改该带;1253457897 360轻应用
	if(ref==1252950557||ref==1253457897){
		$(".down_app").hide();
		$(".zhanbei").hide();
//			document.write("<script type=\"text/javascript\" src=\"http://m.baidu.com/static/search/light/lightAppAdPlugin.js?docid=6665644&appid=2007309&appname=有妖气&storepath=you-yao-qi-man-hua/id557522169\"><\/script>");//百度轻应用
	}
	if(ref==1253031006){//uc下载的不显示app下载
		$(".down_app").hide();
		$(".zhanbei").hide();
	}
});
//底部app下载关闭事件
$(function(){
	$("#down_app_close").click(function(){
		$("#down_app").hide();
		$(".zhanbei").hide();
		$.cookie('showAppDownload','false',{expires:1,path:'/'});
	});
});

$(function() {
	reloadFooter();
});
//底部显示登录状态
$(function(){
	var user = get_user();
	var a = $('#footer').find('a.bor_right_d').eq(0);
	if(user!=null && user.id>0){
		var xxauthkey= user.nickname;
		a.attr('href',pUrl+'/user/info');
		a.removeAttr('onclick');
		a.text(xxauthkey);
	}
});
